<%@ page language="java" contentType="text/html; charset=UTF-8"   pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台管理系统——登录</title>
<link rel="stylesheet" type="text/css" href="pages/extjs2.0/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="pages/css/style.css" />
<script type="text/javascript" src="pages/extjs2.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="pages/extjs2.0/ext-all.js"></script>
<script type="text/javascript" src="pages/extjs2.0/source/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="pages/extjs2.0/ext/themeChange.js"></script>
</head>
<script type="text/javascript">
	Ext.QuickTips.init();
	var LoginWindow = Ext.extend(Ext.Window, {
			//窗口名称   
            title : "系统登陆",
            //窗口宽度   
            width : 280,
            //窗口高度   
            height : 200,
            //不显示展开工具按钮
            collapsible : false,
            //不显示关闭工具按钮
            closable : false, 
            defaults : {   
                border : false  
            },   
		    layout:"fit",  
		    plain:true,
		    bodyStyle:"padding:2px;",
		    maximizable:false,
		    closeAction:"close",
		    buttonAlign:"center",
            createFormPanel : function() { 
            	function reset() {  
            		 myform.form.reset();
            	}
            	
	        	function login() {  
	            	if(myform.getForm().isValid())
		            { 
		               myform.form.submit({   
		                    waitMsg : "正在登陆......",   
		                    url : "login.action",
		                    method:'POST',   
		                    success : function(form, action) { 
		                     	//跳转主页 
		                        window.location.href = "<%=basePath%>pages/system/index.jsp";   
		                    },   
		                    failure : function(form, action) {   
		                        form.reset();   
		                        if (action.failureType == Ext.form.Action.SERVER_INVALID) {   
		                            Ext.MessageBox.alert("警告", action.result.message);   
		                        }else{   
		                            Ext.MessageBox.alert("登陆失败", action.result.message);   
		                        }   
		                    }   
		                });  
	                } 
	            };
            	
             	 var myform = new Ext.form.FormPanel({
                    bodyStyle : "padding-top:6px",   
                    defaultType : "textfield",   
                    labelAlign : "right",   
                    labelWidth : 55,   
                    labelPad : 5,   
                    frame : true,   
                    defaults : {   
                        allowBlank : false,   
                        width : 158  
                    },
                    //增加表单键盘事件
		           keys:[
		            {
		                key: [10,13],
		                fn:login
		            }],  
		                                 
                    items : [{   
                                cls : "user",   
                                name : "users.username",   
                                fieldLabel : "用户名",   
                                blankText : "用户名不能为空",
                                id : "username",      
                                msgTarget:"side"  
                            }, {   
                                cls : "key",   
                                name : "users.password",   
                                fieldLabel : "密码",   
                                blankText : "密码不能为空",   
                                inputType : "password",   
                                msgTarget:"side"  
                            }, {   
                                cls : "rand",   
                                name : "randCode",   
                                id : "randCode",   
                                fieldLabel : "验证码",   
                                width : "80",   
                                blankText : "验证码不能为空"  
                    }] ,
		            buttons:[
		            {
		                text:'确定',
		                id:'sure',
		                handler:login
		            },
		            {
		                text:'重置',
		                id:'clear',
		                handler:reset
		            }]  
                });
                return  myform;  
            },   
            initComponent : function() {   
                LoginWindow.superclass.initComponent.call(this);   
                this.fp = this.createFormPanel();   
                this.add(this.fp);   
            }   
        });   
  
  	
  	//默认用户名获取焦点
  	function initFocus() {
		var f = Ext.get("username");
		f.focus.defer(100, f); 
	}
	

  	
	Ext.onReady(function() {
	    var win = new LoginWindow();
	    win.on('show', function(){
	    	//initFocus();
	    });
	    win.show();   
	    var bd = Ext.getDom("randCode");   
	    var bd2 = Ext.get(bd.parentNode); 	    
	    bd2.createChild({   
	        tag : "img",
	        src : "imagenumber", 
	        align : "absmiddle"  
	    });                    	 
	  
	}); 
	
</script>
<body>
</body>
</html>